var express = require('express');
var router = express.Router();
var kjx = require('../../util/comm');

/**
 * ejs同步方式生成页面算数试题 
 */
router.get('/shuxue',function (req,res,next){
  res.render('shuxue/shuxue',
    {
      title:'儿子的数学题',
    }
  );
})

/**
 * 为页面jquery方法，提供相应的数据返回
 */
router.post('/createQuest',function (req,res,next){
console.log('===>createQuest');
  var body = req.body;
  //百以内数学题生成
  var questNo = parseInt((body.no == undefined || body.no == null) ? 20 : body.no);//生成的试题个数
  var maxShu = parseInt(body.max);//最大数
  var minShu = parseInt(body.min);//最小数
  var questions = [];
  while(questions.length < questNo){
    var f = kjx.mkNumber(minShu,maxShu);
    var s = kjx.mkNumber(minShu,maxShu);
    if(kjx.chNumber(f + s ,maxShu)){
      questions.push({first:f,second:s});
    }
  } 
  res.send({
    title:'儿子的数学题',
    question : questions
  });

})

module.exports = router;
